﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>版辊信息添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/layui/layui.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
    <link href="~/Content/Scripts/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <span style="margin-top:15px;margin-left:15px">
        <xblock>
            <button class="layui-btn" onclick="saveData()"><i class="layui-icon"></i>保存</button>
            <button class="layui-btn" onclick="closeWin()"><i class="layui-icon">&#x1006;</i>取消</button>
        </xblock>
    </span>

    <div style="margin: 20px; border: 1px solid #dbdbdb;padding:15px">

        <form id="AddForm" class="layui-form layui-col-space5">
            <div class="layui-form-item">
                <input type="hidden" name="id" autocomplete="off" class="layui-input" id="userCode">
                <label class="layui-form-label">
                客户
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="customName" name="customName" autocomplete="off" class="layui-input" onclick="openWin()">
                    <input type="hidden" id="customCode" name="customCode" >
                </div>

                <label class="layui-form-label">
                    存放位置
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="weizhi" name="weizhi" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <input type="hidden" name="id"  id="id">

                <label  class="layui-form-label">
                    版长
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="banchang" name="banchang"  autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">
                    键槽
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="jiancao" name="jiancao" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    共用版
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="gongyongban" name="gongyongban" autocomplete="off" class="layui-input">
                </div>
                <label for="L_email" class="layui-form-label">
                    版周
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="banzhou" name="banzhou" autocomplete="off" class="layui-input">

                </div>

               
            </div>

            <div class="layui-form-item">

                <label  class="layui-form-label">
                    版支数
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="banzhi" name="banzhi"  autocomplete="off" class="layui-input">
                </div>
                <label for="L_email" class="layui-form-label">
                    支数明细
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="banzhimingxi" name="banzhimingxi" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    制版厂家
                </label>
                <div class="layui-input-inline">
                    <select id="zhibanchangjia" name="zhibanchangjia" class="bzbcj">
                        选择厂家
                    </select>
                </div>
                <label for="L_email" class="layui-form-label">
                   版眼大小
                </label>
                <div class="layui-input-inline">
                    <select id="banyan" name="banyan" class="bydx">
                        版眼大小
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
             
                <label for="L_email" class="layui-form-label">
                    版号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="banhao" name="banhao" autocomplete="off" class="layui-input">
                </div>
                <label for="L_email" class="layui-form-label">
                    货号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="proCode" name="proCode" autocomplete="off" class="layui-input" onclick="chooseProduct()">
                    <input type="hidden" id="selectProduct" name="selectProduct">
                    <input type="hidden" id="pCode" name="pCode">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                  存货名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="proName" name="proName" autocomplete="off" class="layui-input" >
                </div>
                <label for="L_email" class="layui-form-label">
                   规格型号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="spec" name="spec" autocomplete="off" class="layui-input">
                </div>
            </div>
            <input type="hidden" name="typeCode" id="typeCode" />
        </form>

    </div>
</body>
</html>
<script type="text/javascript">
    $(function () {
        var dataId = getUrlVariable("dataId");
        var type = getUrlVariable("type");
        CommonData("zbcj", "bzbcj");
        CommonData('ys-bydx', "bydx");
        if (dataId != "0") {
            $("input[ name='id']").val(dataId);
            loadData(dataId);
        } else {
            $("input[ name='typeCode']").val(type);
        }
        layui.use('form', function () {
            var form = layui.form;
            form.render();
        });
    });
    //加载数据信息
    function loadData(dataId) {
        $.ajax({
            url: "../Basis/GetBanGunInfo",
            type: "post",
            data: { dataId: dataId },
            success: function (data) {
                if (data.Result) {

                    $.each(data.Data[0], function (name, value) {
                        if (name == "isDefault" || name == "status" || name == "zhibanchangjia" || name == "banyan") {
                            $("#"+ name +" option[value='" + value + "'] ").attr("selected", true)
                        }
                        $("input[ name='" + name + "']").val(value);
                    });
                    $("#parValue").html(data.Data[0]["parValue"]);
                  
                    // 设置下拉选择框的默认选项
                    $('#bStatus').val(data.Data[0]['bStatus']);
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        });

    }
    function openWin() {
        InfoOpenPage("../Common/selectCustomer?isSingle=1", "选择客户", "90%", "90%");
    }
    //保存数据
    function saveData() {
        $.ajax({
            url: "../Basis/saveBanGunInfo",
            data: { datas: JSON.stringify(FormToJson("AddForm")) },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    var id = $("input[ name='id']").val();
                    var msg = "信息修改成功";
                    if (id == "0" || id == "") {
                        msg = "信息添加成功";
                    }
                    layer.alert(msg, { icon: 6 }, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
    //存货选择
    function chooseProduct() {
            layer.open({
                type: 2,
                maxmin: false,
                fix: false,
                title: "选择存货档案",
                area: ['90%', '90%'],
                closeBtn: 1,
                shadeClose: true,
                content: "../Common/selectProduct?isSingle=1&typeCode=",
                //关闭弹出框的回调函数，不管弹出框是手动关闭还是通过脚本进行关闭，都执行
                end: function () {
                    var infos = $("input[ name='selectProduct']").val();
                    var json = JSON.parse(infos);
                    $("input[ name='proCode']").val(json.proCode);
                    $("input[ name='proName']").val(json.proName);
                    $("input[ name='spec']").val(json.spec);
                    checkBanGun(json.proCode)
                }
            });
    }
    /**
    验证版辊是否存在
    **/
    function checkBanGun(proCode) {
        $.ajax({
            url: "../Basis/CheckProductBanGun",
            type: "post",
            data: { proCode: proCode },
            success: function (data) {
                if (!data.Result) {
                    layer.msg(data.Message);
                }
            }
        });

    }
</script>